<template>
    <div id="dialog">
        <el-dialog
            :title="classDia.title"
            :visible.sync="classDia.show"
            width="80%"
            >
                <div class="form">

                    <el-table
                        :data="classData"
                        height="400"
                        border
                        style="width: 100%">
                        <el-table-column
                        prop="id"
                        label="课程ID"
                        >
                        </el-table-column>
                        <el-table-column
                        prop="name"
                        label="课程"
                        >
                        </el-table-column>
                        <el-table-column
                        prop="peoplenum"
                        label="人数">
                        </el-table-column>
                        <el-table-column
                        prop="classnum"
                        label="剩余数量">
                        </el-table-column>

                        <el-table-column
                        prop="classnum"
                        width="300"
                        label="编辑">
                            <template slot-scope="scope">
                                
                                <div class="input" >
                                    <el-input placeholder="修改课程数量" v-model="scope.row.num" class="input-with-select">
                                        <el-button slot="append" icon="el-icon-edit" @click="editNum(scope.row)">修改</el-button>
                                    </el-input>
                                </div>
                            </template>

                        </el-table-column>
                    </el-table>
                </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="classDia.show = false">关闭</el-button>
                <!-- <el-button type="primary" @click="SubForm">确 定</el-button> -->
            </span>
            </el-dialog>
    </div>
</template>

<script>
    export default {
        props: {
            classDia: Object,
            classData: Array,
        },
        data() {
            return {
                MenuList: [],
                options: [],
                status: [
                    { value: 1, label: "开启"},
                    { value: 2, label: "关闭"},
                ],
                classnum: "",
            }
        },
        computed: {
            token() {
                return localStorage.token;
            }
        },
        mounted() {
            
        },
        methods: {
           
            // 是否编辑
            async editNum(item) {
                // console.log(this.classDia);
                
                if (item.num) {
                   let res = await this.$axios.post("/admin/user/agentclass", { token: this.token, userid: this.classDia.userid, id: item.id, classnum: item.num } )
                   //console.log(res);
                   
                   if (res.data.code == 202 || res.data.code == 204) {
                       this.$message.success("更新成功")
                       this.$emit("update")
                       this.classDia.show = false 
                       
                   } else {
                       this.$message.success("更新失败")
                       this.$emit("update")
                       this.classDia.show = false 
                   }
                }
            },
          
            // 提交添加或修改
            async  SubForm() {
               this.classDia.show = false
            },

        }
    }
</script>

<style lang="scss" scoped>
.sltbox {
    width: 148px;
    height: 148px;
    margin: 0 10px;
    img {
        width: 148px;
        height: 148px;
    }
}
.up {
    width: 100%;
    display: flex;
}
</style>